package cn.powerone.scm.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.powerone.common.annotation.Log;
import cn.powerone.common.core.controller.BaseController;
import cn.powerone.common.core.domain.AjaxResult;
import cn.powerone.common.enums.BusinessType;
import cn.powerone.scm.domain.ScmCustomerAddress;
import cn.powerone.scm.service.IScmCustomerAddressService;
import cn.powerone.common.utils.poi.ExcelUtil;
import cn.powerone.common.core.page.TableDataInfo;

/**
 * 客户地址Controller
 * 
 * @author PowerOne
 * @date 2025-06-23
 */
@RestController
@RequestMapping("/scm/customerAddress")
public class ScmCustomerAddressController extends BaseController
{
    @Autowired
    private IScmCustomerAddressService scmCustomerAddressService;

    /**
     * 查询客户地址列表
     */
    @PreAuthorize("@ss.hasPermi('scm:customerAddress:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScmCustomerAddress scmCustomerAddress)
    {
        startPage();
        List<ScmCustomerAddress> list = scmCustomerAddressService.selectScmCustomerAddressList(scmCustomerAddress);
        return getDataTable(list);
    }

    /**
     * 导出客户地址列表
     */
    @PreAuthorize("@ss.hasPermi('scm:customerAddress:export')")
    @Log(title = "客户地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScmCustomerAddress scmCustomerAddress)
    {
        List<ScmCustomerAddress> list = scmCustomerAddressService.selectScmCustomerAddressList(scmCustomerAddress);
        ExcelUtil<ScmCustomerAddress> util = new ExcelUtil<ScmCustomerAddress>(ScmCustomerAddress.class);
        util.exportExcel(response, list, "客户地址数据");
    }

    /**
     * 获取客户地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('scm:customerAddress:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scmCustomerAddressService.selectScmCustomerAddressById(id));
    }

    /**
     * 新增客户地址
     */
    @PreAuthorize("@ss.hasPermi('scm:customerAddress:add')")
    @Log(title = "客户地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScmCustomerAddress scmCustomerAddress)
    {
        return toAjax(scmCustomerAddressService.insertScmCustomerAddress(scmCustomerAddress));
    }

    /**
     * 修改客户地址
     */
    @PreAuthorize("@ss.hasPermi('scm:customerAddress:edit')")
    @Log(title = "客户地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScmCustomerAddress scmCustomerAddress)
    {
        return toAjax(scmCustomerAddressService.updateScmCustomerAddress(scmCustomerAddress));
    }

    /**
     * 删除客户地址
     */
    @PreAuthorize("@ss.hasPermi('scm:customerAddress:remove')")
    @Log(title = "客户地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scmCustomerAddressService.deleteScmCustomerAddressByIds(ids));
    }
}
